﻿using Serilog.Enrichers.Sensitive;
using System.Text.RegularExpressions;

namespace Shared.Service.Logging.Serilog
{
    public class LogIdCardMasking : RegexMaskingOperator
    {
        public LogIdCardMasking() : base(@"\b\d{17}(\d|x|X)\b")
        {
        }

        protected override string PreprocessMask(string mask, Match match)
        {
            return Regex.Replace(match.Value, "(\\d{3})\\d{13}(\\d|x|X)", $"$1{mask.PadRight(6, mask.ToCharArray()[0])}$2");
        }
    }
}
